<template>
  <div>
    <template v-for="(item, index) in flagArr">
      <el-tag :index="index" :type="item == '1'?'success':'danger'" v-if="checkDateArr[index]">
        {{ dealDate(checkDateArr[index]) }}
      </el-tag>
    </template>
  </div>
</template>

<script>
export default {
  name: "CheckTag",
  props: {
    flag: {
      type: String,
      default: "",
    },
    checkDate: {
      type: String,
      default: "",
    },
    days: {
      type: Number,
      default: 7,
    },
  },
  data() {
    return {
      daysArr: [],
      dateArr: [],
    };
  },
  computed: {
    flagArr() {
      if (this.flag !== null && typeof this.flag !== 'undefined') {
        return this.flag.split('');
      } else {
        return [];
      }
    },

    checkDateArr() {
      if (this.checkDate != null && typeof this.checkDate !== 'undefined') {
        let arr = this.checkDate.split(",");
        return arr.slice(0, this.days);
      }
    }

  },
  created() {
    // this.getNearlyDay(30);
  },
  methods: {

    dealDate(value) {
      if(value && value.length > 0){
        return value.substr(5, 5);
      }
    },
/*

    getNearlyDay(days) {
      let date = new Date();
      for (let i = 0; i < days; i++) {
        //今天加上前6天
        let dateItem = new Date(date.getTime() - i * 24 * 60 * 60 * 1000) //使用当天时间戳减去以前的时间毫秒（小时*分*秒*毫秒）
        // let y = dateItem.getFullYear() //获取年份
        let m = dateItem.getMonth() + 1 //获取月份js月份从0开始，需要+1
        let d = dateItem.getDate() //获取日期
        m = this.addDate0(m) //给为单数的月份补零
        d = this.addDate0(d) //给为单数的日期补零
        let valueItem = m + '-' + d //组合
        this.daysArr.push(valueItem) //添加至数组
      }
    },
*/

    //给日期加0
/*
    addDate0(time) {
      if (time.toString().length == 1) {
        time = '0' + time.toString()
      }
      return time
    },
*/

  },
}
</script>

<style scoped>
  .el-tag + .el-tag {
    margin: 2px 3px;
  }

  .el-tag {
    margin-left: 3px;
    padding: 0 3px;
  }

  .el-tag.el-tag--success {
    background-color: #e7faf0;
    border-color: #d0f5e0;
    color: #088d41;
  }
</style>
